using HarmonyLib;
using RimWorld;
using System.Reflection;
using Verse;
using System.Reflection.Emit;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;
using Verse.AI;
using RimWorld.Planet;

namespace RimZombieGirl
{
    public static class GenePatcher
    {
        // Patch AddGene(GeneDef geneDef, bool xenogene)
        [HarmonyPatch(typeof(Pawn_GeneTracker), nameof(Pawn_GeneTracker.AddGene))]
        [HarmonyPrefix]
        public static bool Prefix_AddGene(Pawn_GeneTracker __instance, Gene gene, bool isXenogene)
        {
            if (gene != null && gene is IGeneChangeListener listener)
            {
                // 通知基因变化
                if (!listener.Notify_OnGeneChange(gene, 1)) // 1 表示新增
                {
                    return false; // 阻止执行原方法
                }
            }
            return true;
        }

        // Patch RemoveGene(Gene gene)
        [HarmonyPatch(typeof(Pawn_GeneTracker), nameof(Pawn_GeneTracker.RemoveGene))]
        [HarmonyPrefix]
        public static bool Prefix_RemoveGene(Pawn_GeneTracker __instance, Gene gene)
        {
            if (gene != null && gene is IGeneChangeListener listener)
            {
                // 通知基因变化
                if (!listener.Notify_OnGeneChange(gene, -1)) // -1 表示移除
                {
                    return false; // 阻止执行原方法
                }
            }
            return true;
        }
    }
}